package com.upb.webserver.dao.mapper;

import com.upb.webserver.common.pojo.rest.fisco.data.resp.ChainInfo;
import com.upb.webserver.dao.entity.TbChain;
import com.upb.webserver.dao.entity.TbChainExample;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import java.util.List;
import java.util.Optional;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;

public interface TbChainMapper {

    @Select({ "select", "name", "from tb_chain", "where id = #{chainId,jdbcType=INTEGER}" })
    @Results({ @Result(column = "name", property = "name", jdbcType = JdbcType.VARCHAR) })
    String selectNameByPrimaryKey(@Param("chainId") Integer chainId);

    @Select({ "select", TbChainSqlProvider.ALL_COLUMN_FIELDS, "from tb_chain", "where name = #{name,jdbcType=VARCHAR}" })
    @Results({ @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true), @Result(column = "remote_id", property = "remoteId", jdbcType = JdbcType.INTEGER), @Result(column = "name", property = "name", jdbcType = JdbcType.VARCHAR), @Result(column = "version", property = "version", jdbcType = JdbcType.VARCHAR), @Result(column = "chain_type", property = "chainType", jdbcType = JdbcType.TINYINT), @Result(column = "encryption_id", property = "encryptionId", jdbcType = JdbcType.TINYINT), @Result(column = "create_status", property = "createStatus", jdbcType = JdbcType.TINYINT), @Result(column = "create_from_platform", property = "createFromPlatform", jdbcType = JdbcType.TINYINT), @Result(column = "create_by", property = "createBy", jdbcType = JdbcType.INTEGER), @Result(column = "gmt_create", property = "gmtCreate", jdbcType = JdbcType.TIMESTAMP), @Result(column = "gmt_modified", property = "gmtModified", jdbcType = JdbcType.TIMESTAMP), @Result(column = "description", property = "description", jdbcType = JdbcType.LONGVARCHAR), @Result(column = "remark", property = "remark", jdbcType = JdbcType.LONGVARCHAR) })
    TbChain selectByChainName(@Param("name") String name);

    @Select({ "select * from tb_chain", "where chain_type = #{chainType,jdbcType=TINYINT}" })
    @Results({ @Result(column = "id", property = "chainId", jdbcType = JdbcType.INTEGER, id = true), @Result(column = "name", property = "chainName", jdbcType = JdbcType.VARCHAR), @Result(column = "chain_type", property = "chainType", jdbcType = JdbcType.TINYINT), @Result(column = "chain_type", property = "encryptType", jdbcType = JdbcType.TINYINT), @Result(column = "description", property = "description", jdbcType = JdbcType.VARCHAR) })
    List<ChainInfo> getChainInfoList(@Param("chainType") Byte chainType);


    @Select({"select count(*) from tb_chain where create_status >= 6"})
    int getCountChainOfExist();

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_chain
     *
     * @mbg.generated
     */
    @SelectProvider(type = TbChainSqlProvider.class, method = "countByExample")
    long countByExample(TbChainExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_chain
     *
     * @mbg.generated
     */
    @DeleteProvider(type = TbChainSqlProvider.class, method = "deleteByExample")
    int deleteByExample(TbChainExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_chain
     *
     * @mbg.generated
     */
    @Delete({ "delete from tb_chain", "where id = #{id,jdbcType=INTEGER}" })
    int deleteByPrimaryKey(Integer id);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_chain
     *
     * @mbg.generated
     */
    @Insert({ "insert into tb_chain (remote_id, name, ", "version, chain_type, ", "encryption_id, create_status, ", "create_from_platform, create_by, ", "gmt_create, gmt_modified, ", "description, remark)", "values (#{remoteId,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, ", "#{version,jdbcType=VARCHAR}, #{chainType,jdbcType=TINYINT}, ", "#{encryptionId,jdbcType=TINYINT}, #{createStatus,jdbcType=TINYINT}, ", "#{createFromPlatform,jdbcType=TINYINT}, #{createBy,jdbcType=INTEGER}, ", "#{gmtCreate,jdbcType=TIMESTAMP}, #{gmtModified,jdbcType=TIMESTAMP}, ", "#{description,jdbcType=LONGVARCHAR}, #{remark,jdbcType=LONGVARCHAR})" })
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "id", before = false, resultType = Integer.class)
    int insert(TbChain record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_chain
     *
     * @mbg.generated
     */
    @InsertProvider(type = TbChainSqlProvider.class, method = "insertSelective")
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "id", before = false, resultType = Integer.class)
    int insertSelective(TbChain record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_chain
     *
     * @mbg.generated
     */
    @SelectProvider(type = TbChainSqlProvider.class, method = "selectByExampleWithBLOBs")
    @Results({ @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true), @Result(column = "remote_id", property = "remoteId", jdbcType = JdbcType.INTEGER), @Result(column = "name", property = "name", jdbcType = JdbcType.VARCHAR), @Result(column = "version", property = "version", jdbcType = JdbcType.VARCHAR), @Result(column = "chain_type", property = "chainType", jdbcType = JdbcType.TINYINT), @Result(column = "encryption_id", property = "encryptionId", jdbcType = JdbcType.TINYINT), @Result(column = "create_status", property = "createStatus", jdbcType = JdbcType.TINYINT), @Result(column = "create_from_platform", property = "createFromPlatform", jdbcType = JdbcType.TINYINT), @Result(column = "create_by", property = "createBy", jdbcType = JdbcType.INTEGER), @Result(column = "gmt_create", property = "gmtCreate", jdbcType = JdbcType.TIMESTAMP), @Result(column = "gmt_modified", property = "gmtModified", jdbcType = JdbcType.TIMESTAMP), @Result(column = "description", property = "description", jdbcType = JdbcType.LONGVARCHAR), @Result(column = "remark", property = "remark", jdbcType = JdbcType.LONGVARCHAR) })
    List<TbChain> selectByExampleWithBLOBs(TbChainExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_chain
     *
     * @mbg.generated
     */
    @SelectProvider(type = TbChainSqlProvider.class, method = "selectByExample")
    @Results({ @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true), @Result(column = "remote_id", property = "remoteId", jdbcType = JdbcType.INTEGER), @Result(column = "name", property = "name", jdbcType = JdbcType.VARCHAR), @Result(column = "version", property = "version", jdbcType = JdbcType.VARCHAR), @Result(column = "chain_type", property = "chainType", jdbcType = JdbcType.TINYINT), @Result(column = "encryption_id", property = "encryptionId", jdbcType = JdbcType.TINYINT), @Result(column = "create_status", property = "createStatus", jdbcType = JdbcType.TINYINT), @Result(column = "create_from_platform", property = "createFromPlatform", jdbcType = JdbcType.TINYINT), @Result(column = "create_by", property = "createBy", jdbcType = JdbcType.INTEGER), @Result(column = "gmt_create", property = "gmtCreate", jdbcType = JdbcType.TIMESTAMP), @Result(column = "gmt_modified", property = "gmtModified", jdbcType = JdbcType.TIMESTAMP) })
    List<TbChain> selectByExample(TbChainExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_chain
     *
     * @mbg.generated
     */
    @Select({ "select", "id, remote_id, name, version, chain_type, encryption_id, create_status, create_from_platform, ", "create_by, gmt_create, gmt_modified, description, remark", "from tb_chain", "where id = #{id,jdbcType=INTEGER}" })
    @Results({ @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true), @Result(column = "remote_id", property = "remoteId", jdbcType = JdbcType.INTEGER), @Result(column = "name", property = "name", jdbcType = JdbcType.VARCHAR), @Result(column = "version", property = "version", jdbcType = JdbcType.VARCHAR), @Result(column = "chain_type", property = "chainType", jdbcType = JdbcType.TINYINT), @Result(column = "encryption_id", property = "encryptionId", jdbcType = JdbcType.TINYINT), @Result(column = "create_status", property = "createStatus", jdbcType = JdbcType.TINYINT), @Result(column = "create_from_platform", property = "createFromPlatform", jdbcType = JdbcType.TINYINT), @Result(column = "create_by", property = "createBy", jdbcType = JdbcType.INTEGER), @Result(column = "gmt_create", property = "gmtCreate", jdbcType = JdbcType.TIMESTAMP), @Result(column = "gmt_modified", property = "gmtModified", jdbcType = JdbcType.TIMESTAMP), @Result(column = "description", property = "description", jdbcType = JdbcType.LONGVARCHAR), @Result(column = "remark", property = "remark", jdbcType = JdbcType.LONGVARCHAR) })
    TbChain selectByPrimaryKey(Integer id);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_chain
     *
     * @mbg.generated
     */
    @UpdateProvider(type = TbChainSqlProvider.class, method = "updateByExampleSelective")
    int updateByExampleSelective(@Param("record") TbChain record, @Param("example") TbChainExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_chain
     *
     * @mbg.generated
     */
    @UpdateProvider(type = TbChainSqlProvider.class, method = "updateByExampleWithBLOBs")
    int updateByExampleWithBLOBs(@Param("record") TbChain record, @Param("example") TbChainExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_chain
     *
     * @mbg.generated
     */
    @UpdateProvider(type = TbChainSqlProvider.class, method = "updateByExample")
    int updateByExample(@Param("record") TbChain record, @Param("example") TbChainExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_chain
     *
     * @mbg.generated
     */
    @UpdateProvider(type = TbChainSqlProvider.class, method = "updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(TbChain record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_chain
     *
     * @mbg.generated
     */
    @Update({ "update tb_chain", "set remote_id = #{remoteId,jdbcType=INTEGER},", "name = #{name,jdbcType=VARCHAR},", "version = #{version,jdbcType=VARCHAR},", "chain_type = #{chainType,jdbcType=TINYINT},", "encryption_id = #{encryptionId,jdbcType=TINYINT},", "create_status = #{createStatus,jdbcType=TINYINT},", "create_from_platform = #{createFromPlatform,jdbcType=TINYINT},", "create_by = #{createBy,jdbcType=INTEGER},", "gmt_create = #{gmtCreate,jdbcType=TIMESTAMP},", "gmt_modified = #{gmtModified,jdbcType=TIMESTAMP},", "description = #{description,jdbcType=LONGVARCHAR},", "remark = #{remark,jdbcType=LONGVARCHAR}", "where id = #{id,jdbcType=INTEGER}" })
    int updateByPrimaryKeyWithBLOBs(TbChain record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_chain
     *
     * @mbg.generated
     */
    @Update({ "update tb_chain", "set remote_id = #{remoteId,jdbcType=INTEGER},", "name = #{name,jdbcType=VARCHAR},", "version = #{version,jdbcType=VARCHAR},", "chain_type = #{chainType,jdbcType=TINYINT},", "encryption_id = #{encryptionId,jdbcType=TINYINT},", "create_status = #{createStatus,jdbcType=TINYINT},", "create_from_platform = #{createFromPlatform,jdbcType=TINYINT},", "create_by = #{createBy,jdbcType=INTEGER},", "gmt_create = #{gmtCreate,jdbcType=TIMESTAMP},", "gmt_modified = #{gmtModified,jdbcType=TIMESTAMP}", "where id = #{id,jdbcType=INTEGER}" })
    int updateByPrimaryKey(TbChain record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_chain
     *
     * @mbg.generated
     */
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    @Insert({ "<script>", "insert into tb_chain (remote_id, ", "name, version, ", "chain_type, encryption_id, ", "create_status, create_from_platform, ", "create_by, gmt_create, ", "gmt_modified, description, ", "remark)", "values<foreach collection=\"list\" item=\"detail\" index=\"index\" separator=\",\">(#{detail.remoteId,jdbcType=INTEGER}, ", "#{detail.name,jdbcType=VARCHAR}, #{detail.version,jdbcType=VARCHAR}, ", "#{detail.chainType,jdbcType=TINYINT}, #{detail.encryptionId,jdbcType=TINYINT}, ", "#{detail.createStatus,jdbcType=TINYINT}, #{detail.createFromPlatform,jdbcType=TINYINT}, ", "#{detail.createBy,jdbcType=INTEGER}, #{detail.gmtCreate,jdbcType=TIMESTAMP}, ", "#{detail.gmtModified,jdbcType=TIMESTAMP}, #{detail.description,jdbcType=LONGVARCHAR}, ", "#{detail.remark,jdbcType=LONGVARCHAR})</foreach></script>" })
    int batchInsert(List<TbChain> list);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_chain
     *
     * @mbg.generated
     */
    @SelectProvider(type = TbChainSqlProvider.class, method = "getOneByExample")
    @Results({ @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true), @Result(column = "remote_id", property = "remoteId", jdbcType = JdbcType.INTEGER), @Result(column = "name", property = "name", jdbcType = JdbcType.VARCHAR), @Result(column = "version", property = "version", jdbcType = JdbcType.VARCHAR), @Result(column = "chain_type", property = "chainType", jdbcType = JdbcType.TINYINT), @Result(column = "encryption_id", property = "encryptionId", jdbcType = JdbcType.TINYINT), @Result(column = "create_status", property = "createStatus", jdbcType = JdbcType.TINYINT), @Result(column = "create_from_platform", property = "createFromPlatform", jdbcType = JdbcType.TINYINT), @Result(column = "create_by", property = "createBy", jdbcType = JdbcType.INTEGER), @Result(column = "gmt_create", property = "gmtCreate", jdbcType = JdbcType.TIMESTAMP), @Result(column = "gmt_modified", property = "gmtModified", jdbcType = JdbcType.TIMESTAMP), @Result(column = "description", property = "description", jdbcType = JdbcType.LONGVARCHAR), @Result(column = "remark", property = "remark", jdbcType = JdbcType.LONGVARCHAR) })
    Optional<TbChain> getOneByExample(TbChainExample example);
}
